package 剑指offer;


/*
 * Author：江松
 * Date：2023/3/8 10:14
 *
 *
 *
 * 字符串序列：全排列问题
"abc"
["abc","acb","bac","bca","cab","cba"]
"aab"
["aab","aba","baa"]
 */

import javax.print.DocFlavor;
import java.util.*;

public class Main14 {
    //char包装类Character
    boolean vis[]=new boolean[15];
    Set<String> tmp=new HashSet<>();
    String str;
    public void dfs(StringBuilder now,int index) {
        if(index==str.length()){
            tmp.add(now.toString());
            return;
        }
        for(int i=0;i<str.length();++i){
            Character ch=str.charAt(i);
            if(!vis[i]){
                vis[i]=true;
                now.append(ch);
                dfs(now,index+1);
                now.delete(index,index+1);
                vis[i]=false;
            }
        }
    }

    public ArrayList<String> Permutation(String str) {
        this.str=str;
        dfs(new StringBuilder(),0);
        return new ArrayList<>(tmp);
    }
    public static void main(String[] args) {

    }
    }

